package main

import (
	"fmt"
	"strconv"
)

//类型转换

func main() {
	//字符串转int
	s1 := "100"
	i1, err := strconv.Atoi(s1)
	if err != nil {
		fmt.Println("can't convert to int")
	} else {
		fmt.Printf("type : %T value:%#v\n", i1, i1)
	}
	//int转字符串
	str1 := strconv.Itoa(i1)
	fmt.Printf("type : %T value:%#v\n", str1, str1)

	//parse系列函数 用于转换字符串为给定的值
	parseInt, err := strconv.ParseInt(str1, 0, 0)
	if err != nil {
		return
	}
	fmt.Printf("type: %T value:%#v\n", parseInt, parseInt)

	i, err := strconv.ParseInt("-2", 10, 64)
	if err != nil {
		return
	}
	fmt.Println(i)

	formatFunc()
}

func formatFunc() {
	s1 := strconv.FormatBool(true)
	s2 := strconv.FormatFloat(3.1415, 'E', -1, 64)
	s3 := strconv.FormatInt(-2, 16)
	s4 := strconv.FormatUint(2, 16)
	fmt.Println(s1, s2, s3, s4)
}
